from django.test import TestCase
from django.core.urlresolvers import reverse
from django.conf import settings

from .models import Result

class ViewTests(TestCase):
    fixtures = "test_auth", "test_useragents", "test_tests", "test_results"

    def testResultList(self):
        response = self.client.get(reverse('result-list', kwargs=dict(page="1")))
        self.assertContains(response, "List of results")
    
    def testResultDetail(self):
        RESULT_ID = "48532"
        path = reverse('result-detail', args=(RESULT_ID,))
        response = self.client.get(path)
        self.assertContains(response, "Result %s Detail" % RESULT_ID)
    
        delete_path = reverse('result-delete', args=(RESULT_ID,))

        response = self.client.post(delete_path)
        self.assertRedirects(response, settings.LOGIN_URL + "?next=" + delete_path)
        self.assertEqual(Result.objects.filter(pk=RESULT_ID).count(), 1)
        
        self.assertTrue(self.client.login(username="admin", password="admin"))        
        response = self.client.post(delete_path)
        self.assertRedirects(response, "/")
        self.assertEqual(Result.objects.filter(pk=RESULT_ID).count(), 0)

    #def testResultSearch(self):
        # TODO
